home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Tech Arsenal 1
/
Tech Arsenal (Arsenal Computer).ISO
/
tek-02
/
indx18eu.zip
/
IREAD.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1991-03-20
|
4KB
|
182 lines
PROGRAM TestIndexes ;
USES
DOS ,
CRT ,
IndexedFiles ;
CONST
IndexedFileName = 'INDEXED' ;
TYPE
MyRec = RECORD
index : IndexStr ;
name : STRING ;
age : BYTE ;
salary : REAL ;
occurance : INTEGER ;
phone : STRING ;
END ; { MyRec }
VAR
f : IFile ;
temp : MyRec ;
i : INTEGER ;
yourIndex : LONGINT ;
ch : CHAR ;
FUNCTION Index_Convert ( s : STRING )
: STRING ;
BEGIN { Index_Convert }
WHILE ( Length ( s ) < 10 )
DO
BEGIN
s := '0' + s ;
END ; { WHILE }
Index_Convert := s ;
END ; { Index_Convert }
FUNCTION StrNum ( n : LONGINT )
: STRING ;
VAR
s : STRING ;
BEGIN { StrNum }
Str ( n , s ) ;
StrNum := s ;
END ; { StrNum }
BEGIN
ClrScr ;
AssignIndexed ( f , IndexedFileName ) ;
ResetIndexed ( f ) ;
WITH temp
DO
BEGIN
FOR i := 0 TO 20
DO
BEGIN
index := Index_Convert ( StrNum ( i ) ) ;
ReadIndexed ( f , temp , SizeOf ( MyRec ) ) ;
IF ( fileError = 0 )
THEN
BEGIN
WriteLn ;
WriteLn ( 'INDEX : [' , index , ']' ) ;
WriteLn ( ' NAME : ' , name ) ;
WriteLn ( ' AGE : ' , age:3 , ' SALARY: ' , salary:7:2 ) ;
WriteLn ( ' PHONE : ' , phone ) ;
WriteLn ( 'This is occurance # ' , occurance ) ;
ch := ReadKey ;
END { IF }
ELSE
BEGIN
WriteLn ;
WriteLn ( ' Error with index [' , index:10 , ']!' ) ;
WriteLn ( 'This means : ' , IndexedError ( fileError ) ) ;
fileError := 0 ; { Not needed, but ... }
END ; { ELSE }
END ; { FOR i }
WriteLn ;
WriteLn ( 'Press any key to continue. ' ) ;
ch := ReadKey ;
ClrScr ;
Write ( 'Change or add index : ' ) ;
ReadLn ( yourIndex ) ;
index := Index_Convert ( StrNum ( yourIndex ) ) ;
Write ( 'NAME : ' ) ;
ReadLn ( name ) ;
Write ( 'AGE : ' ) ;
ReadLn ( age ) ;
Write ( 'SALARY : ' ) ;
ReadLn ( salary ) ;
Write ( 'PHONE : ' ) ;
ReadLn ( phone ) ;
ClrScr ;
occurance := IndexFileSize ( f.indexFile ) ;
WriteIndexed ( f , temp , SizeOf ( MyRec ) ) ;
FOR i := 0 TO ( yourIndex + 10 )
DO
BEGIN
index := Index_Convert ( StrNum ( i ) ) ;
ReadIndexed ( f , temp , SizeOf ( MyRec ) ) ;
IF ( fileError = 0 )
THEN
BEGIN
WriteLn ;
WriteLn ( 'INDEX : [' , index , ']' ) ;
WriteLn ( ' NAME : ' , name ) ;
WriteLn ( ' AGE : ' , age:3 , ' SALARY: ' , salary:7:2 ) ;
WriteLn ( ' PHONE : ' , phone ) ;
WriteLn ( 'This is occurance # ' , occurance ) ;
ch := ReadKey ;
END { IF }
ELSE
BEGIN
WriteLn ;
WriteLn ( 'File Error! ' , IndexedError ( fileError ) ) ;
fileError := 0 ;
END ; { ELSE }
END ; { FOR i }
END ; { WITH temp }
CloseIndexed ( f ) ;
END.